package com.fjj.cs.util;

import java.util.Arrays;
import java.util.List;

// 自动补全类
public class AutoComplete {
    private Trie trie;

    public AutoComplete(List<String> words) {
        trie = new Trie();
        for (String word : words) {
            trie.insert(word);
        }
    }

    // 获取自动补齐的建议词汇
    public List<String> getSuggestions(String prefix) {
        return trie.findWordsWithPrefix(prefix);
    }

    public static void main(String[] args) {
        // 示例单词列表
        List<String> words = Arrays.asList("苹果", "应用", "应用市场", "蝙蝠", "球", "蝙蝠侠");

        // 创建自动补齐对象
        AutoComplete autoComplete = new AutoComplete(words);

        // 获取自动补齐建议
        List<String> suggestions = autoComplete.getSuggestions("应");
        System.out.println(suggestions);  // 输出 ["应用", "应用市场"]
    }
}
